home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_glimpse.idb / usr / freeware / src / glimpse-3.0 / libtemplate / template / pcindex2soif.c.z / pcindex2soif.c
C/C++ Source or Header  |  1997-09-09  |  7KB  |  217 lines

  1. static char rcsid[] = "$Id: pcindex2soif.c,v 1.13 1995/01/10 16:30:36 hardy Exp $";
  2. /*
  3.  *  pcindex2soif.c - Converts Nebula's PC Index data file into SOIF
  4.  *
  5.  *  Usage: pcindex2soif 
  6.  *
  7.  *  Input data file format:
  8.  *    First line:
  9.  *       ("root1" "root2" ... "rootn")
  10.  *    Other object lines:
  11.  *    (("." "p1" "p2" .. "name") "date" size "desc")
  12.  *    Directory lines:
  13.  *    (("." "p1" "p2" .. "name") "desc" "root")
  14.  *
  15.  *  Has some ugly parsing; anyone know of a good lisp-style data reader in C?
  16.  *  Doesn't work with the Directory lines.
  17.  *
  18.  *  Added the 'Archive-Site' tag.
  19.  *
  20.  *  Darren Hardy, hardy@cs.colorado.edu, July 1994
  21.  *
  22.  *  ----------------------------------------------------------------------
  23.  *  Copyright (c) 1994, 1995.  All rights reserved.
  24.  *  
  25.  *          Mic Bowman of Transarc Corporation.
  26.  *          Peter Danzig of the University of Southern California.
  27.  *          Darren R. Hardy of the University of Colorado at Boulder.
  28.  *          Udi Manber of the University of Arizona.
  29.  *          Michael F. Schwartz of the University of Colorado at Boulder. 
  30.  *  
  31.  *  This copyright notice applies to all code in Harvest other than
  32.  *  subsystems developed elsewhere, which contain other copyright notices
  33.  *  in their source text.
  34.  *  
  35.  *  The Harvest software was developed by the Internet Research Task
  36.  *  Force Research Group on Resource Discovery (IRTF-RD).  The Harvest
  37.  *  software may be used for academic, research, government, and internal
  38.  *  business purposes without charge.  If you wish to sell or distribute
  39.  *  the Harvest software to commercial clients or partners, you must
  40.  *  license the software.  See
  41.  *  http://harvest.cs.colorado.edu/harvest/copyright,licensing.html#licensing.
  42.  *  
  43.  *  The Harvest software is provided ``as is'', without express or
  44.  *  implied warranty, and with no support nor obligation to assist in its
  45.  *  use, correction, modification or enhancement.  We assume no liability
  46.  *  with respect to the infringement of copyrights, trade secrets, or any
  47.  *  patents, and are not responsible for consequential damages.  Proper
  48.  *  use of the Harvest software is entirely the responsibility of the user.
  49.  *  
  50.  *  For those who are using Harvest for non-commercial purposes, you may
  51.  *  make derivative works, subject to the following constraints:
  52.  *  
  53.  *  - You must include the above copyright notice and these accompanying 
  54.  *    paragraphs in all forms of derivative works, and any documentation 
  55.  *    and other materials related to such distribution and use acknowledge 
  56.  *    that the software was developed at the above institutions.
  57.  *  
  58.  *  - You must notify IRTF-RD regarding your distribution of the 
  59.  *    derivative work.
  60.  *  
  61.  *  - You must clearly notify users that your are distributing a modified 
  62.  *    version and not the original Harvest software.
  63.  *  
  64.  *  - Any derivative product is also subject to the restrictions of the 
  65.  *    copyright, including distribution and use limitations.
  66.  */
  67. #include <stdio.h>
  68. #include <stdlib.h>
  69. #include <string.h>
  70. #include "util.h"
  71. #include "url.h"
  72. #include "template.h"
  73.  
  74. /*
  75.  *  grab_wrapped_value - returns the text of the largest value wrapped by 
  76.  *  char c[0] and char c[1]
  77.  */
  78. char *grab_wrapped_value(buf, c)
  79. char **buf, *c;
  80. {
  81.     static char s[BUFSIZ];
  82.     char *q;
  83.  
  84.     if ((q = strchr(*buf, c[0])) == NULL) 
  85.         return(NULL);
  86.     *buf = q + 1;                /* mark beginning */
  87.  
  88.     strcpy(s, *buf);            /* copy */
  89.     if ((q = strrchr(s, c[1])) != NULL) {
  90.         *q = '\0';            /* terminate match */
  91.         q = strrchr(*buf, c[1]);
  92.         *buf = q + 1;            /* advance buf ptr */
  93.     } else {
  94.         return(NULL);    
  95.     }
  96.     return(s);
  97. }
  98.  
  99.  
  100. /*
  101.  *  grab_next_value - returns the text in the next smallest value wrapped 
  102.  *  by char c[0] and char c[1]
  103.  */
  104. char *grab_next_value(buf, c)
  105. char **buf, *c;
  106. {
  107.     static char s[BUFSIZ];
  108.     char *q;
  109.  
  110.     if ((q = strchr(*buf, c[0])) == NULL) 
  111.         return(NULL);
  112.     *buf = q + 1;                /* mark beginning */
  113.  
  114.     strcpy(s, *buf);            /* copy */
  115.     if ((q = strchr(s, c[1])) != NULL) {
  116.         *q = '\0';            /* terminate match */
  117.         q = strchr(*buf, c[1]);
  118.         *buf = q + 1;            /* advance buf ptr */
  119.     } else {
  120.         return(NULL);    
  121.     }
  122.     return(s);
  123. }
  124.  
  125. int main(argc, argv)
  126. int argc;
  127. char *argv[];
  128. {
  129.     char buf[BUFSIZ], url[BUFSIZ];
  130.     char *s, *q, *p, *tmp, *line, *tmp2;
  131.     URL *rootup;
  132.     char archive_site[BUFSIZ];
  133.     Template *t;
  134.  
  135.     strcpy(archive_site, "Unknown");
  136.     init_log(stderr, stderr);
  137. #ifdef HAVE_SETLINEBUF
  138.     setlinebuf(stderr);
  139.     setlinebuf(stdout);
  140. #endif
  141.  
  142.     /* Grab the Root URL from the first line of the data file */
  143.     if (fgets(buf, BUFSIZ, stdin) == NULL) 
  144.         fatal("Cannot read first line.\n");
  145.  
  146.     tmp = buf;
  147.     tmp2 = grab_wrapped_value(&tmp, "()");
  148.     if ((q = grab_next_value(&tmp2, "\"\"")) == NULL)
  149.         fatal("Cannot read root URL.\n");
  150.     if ((rootup = url_open(q)) == NULL)
  151.         fatal("Cannot parse URL: %s\n", q);
  152.     if (strstr(rootup->url, "cica") != NULL) {
  153.         strcpy(archive_site, "CICA DOS");
  154.     } else if (strstr(rootup->url, "garbo") != NULL) {
  155.         strcpy(archive_site, "Garbo DOS (Finland)");
  156.     } else if (strstr(rootup->url, "hobbes") != NULL) {
  157.         strcpy(archive_site, "Hobbes OS/2");
  158.     } else if (strstr(rootup->url, "ulowell") != NULL) {
  159.         strcpy(archive_site, "U. Lowell DOS Games");
  160.     } else if (strstr(rootup->url, "oakland") != NULL) {
  161.         strcpy(archive_site, "Oakland U. DOS");
  162.     } else if (strstr(rootup->url, "umich") != NULL) {
  163.         strcpy(archive_site, "U. Michigan DOS");
  164.     }
  165.  
  166.     /* Now read all of the lines */
  167.     while (fgets(buf, BUFSIZ, stdin) != NULL) {
  168.         strcpy(url, rootup->url);
  169.  
  170.         /* Grab the entry in parens */
  171.         tmp = buf;
  172.         line = grab_wrapped_value(&tmp, "()");
  173.         tmp = strdup(line);
  174.  
  175.         /* Build the URL */
  176.         s = grab_next_value(&tmp, "()");
  177.         tmp2 = strdup(s);
  178.         while ((p = grab_next_value(&tmp2, "\"\"")) != NULL) {
  179.             if (!strcmp(p, "."))
  180.                 continue;
  181.             strcat(url, "/");
  182.             strcat(url, p);
  183.         }
  184.  
  185.         if ((t = create_template(NULL, url)) == NULL)
  186.             fatal("Cannot create a template for URL: %s\n", url);
  187.  
  188.         /* Grab the Date */
  189.         if ((p = grab_next_value(&tmp, "\"\"")) == NULL)
  190.             fatal("Could not grab the date: %s\n", buf);
  191.  
  192.         t->list = create_AVList("Archive-Site", archive_site,
  193.                     strlen(archive_site));
  194.  
  195.         if (p != NULL && strlen(p) >= 6) /* yymmdd */
  196.             add_AVList(t->list, "ASCII-Date", p, strlen(p));
  197.  
  198.         /* Grab the size */
  199.         if ((p = grab_next_value(&tmp, "  ")) == NULL)
  200.             fatal("Could not grab the size: %s\n", buf);
  201.         if (strcmp(p, "0") != 0 && strlen(p) > 0) 
  202.             add_AVList(t->list, "File-Size", p, strlen(p));
  203.  
  204.         /* Grab the Description */
  205.         if ((p = grab_next_value(&tmp, "\"\"")) == NULL)
  206.             fatal("Could not grab the description: %s\n", buf);
  207.         if (p != NULL && strlen(p) > 0)
  208.             add_AVList(t->list, "Description", p, strlen(p));
  209.  
  210.         init_print_template(stdout);
  211.         print_template(t);
  212.         finish_print_template();
  213.         free_template(t);
  214.     }
  215.     exit(0);
  216. }
  217.